package com.hellobike.haxing.web.shop;

import com.alibaba.fastjson.JSON;
import com.hellobike.haxing.order.api.IOrderRewardApi;
import com.hellobike.haxing.order.api.IMonthRewardService;
import com.hellobike.haxing.order.model.vo.MonthRewardVo;
import com.hellobike.haxing.order.result.Result;
import com.hellobike.haxing.request.order.OrderRewardRequest;
import com.hellobike.haxing.response.distribution.OrderRewardResponse;
import com.hellobike.haxing.user.vo.UserVo;
import com.hellobike.haxing.util.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "下单任务")
@RestController
@RequestMapping(value = "/order-reward")
@Slf4j
public class OrderRewardController {

    @Reference(version = "1.0.0")
    private IOrderRewardApi orderRewardApi;

    @Reference(version = "1.0.0")
    private IMonthRewardService monthRewardService;

    @Autowired
    private UserUtil userUtil;

    @ApiOperation("生效中的下单任务")
    @PostMapping(value = "/info")
    public Result<OrderRewardResponse> doingActivity() {

        Result<OrderRewardResponse> responseResult = new Result<>();
        responseResult.setData(new OrderRewardResponse());
        UserVo userVo = userUtil.getUser();
        responseResult.getData().setOrderRewardStats(orderRewardApi.getOrderRewardStats(userVo.getShopVo().getId()));
        responseResult.getData().setOrderRewardVo(orderRewardApi.getOrderReward(userVo.getShopVo().getId()));
        return responseResult;
    }

    @ApiOperation("领取任务奖励")
    @PostMapping(value = "/apply")
    public Result<Integer> apply(@RequestBody OrderRewardRequest rewardRequest) {
        log.info("started-youxuan-shp-apply:{}", JSON.toJSONString(rewardRequest));
        Result<Integer> result = orderRewardApi.apply(userUtil.getUser().getShopVo().getId(), rewardRequest.getStep());
        log.info("reward-result:{}", JSON.toJSONString(result));
        return result;
    }

    @ApiOperation("获取月度达标奖励信息")
    @PostMapping(value = "/monthRewardInfo")
    public Result<MonthRewardVo> getMonthRewardInfo() {
        Result<MonthRewardVo> responseResult = new Result<>();
        UserVo userVo = userUtil.getUser();
        MonthRewardVo monthRewardVo = monthRewardService.getMonthRewardInfo(userVo.getId(), userVo.getShopVo().getId());
        responseResult.setData(monthRewardVo);
        return responseResult;
    }

    @ApiOperation("领取月度达标奖励")
    @PostMapping(value = "/pickMonthReward")
    public Result<Integer> pickMonthReward() {
        Result<Integer> responseResult = new Result<>();
//        UserVo userVo = userUtil.getUser();
//        MonthRewardVo monthRewardVo = monthRewardService.getMonthRewardInfo(userVo.getId(), userVo.getShopVo().getId());
        responseResult.setData(1);
        return responseResult;
    }

}
